package th;

/**
 * @author Mark
 * @version 1.0
 * @date 2020/5/24 10:29
 * @description 线程状态
 */
public class ThreadState {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 4; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("#######################");
            }
        });

        // NEW
        Thread.State state = thread.getState();
        System.out.println("state1 = " + state);

        // RUNNABLE
        thread.start();
        state = thread.getState();
        System.out.println("state2 = " + state);

        // TIMED_WAITING (终止之后就不能启动)
        while (state != Thread.State.TERMINATED) {
            Thread.sleep(100);
            state = thread.getState();
            System.out.println("state3 = " + state);
        }

    }
}
